#!/bin/bash

if [ -d "$1" ]; then
    find "$1" -mindepth 1 -maxdepth 1 -type d -not -path '*/\.*' -print0 \
        | while read -d '' -r dir; do
            count=0
            find "$dir" -type f \( -name '*.py' -o -name '*.java' \) -print0 \
                | while read -d '' -r file; do
                    count=$(($count + $(cat "$file" | grep -v '^\s*$' | wc -l)))
                done
            if [ "$count" -gt 0 ]; then
                printf "%5d lines in directory %s\n" "$count" "$dir"
            fi
        done \
        | sort -nr
else
    echo "Usage: $0 DIRECTORY"
fi
